﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iShoppingDTO;

namespace iShoppingDAO
{
    public class MultimediaDAO
    {
        public static int LayMaMulti()
        {
            string selectCommand = "Select max(MaMT) From Multimedia";
            int num = 0;
            try
            {
                num = (int)DataProvider.ExecuteScalar(selectCommand);
            }
            catch (Exception)
            {
            }
            num++;
            return num;
        }

        public static int ThemMultimedia(MultimediaDTO info)
        {
            int firstcode = LayMaMulti();
            try
            { 
                info.MaMT = firstcode;
                string sql = string.Format("insert into MULTIMEDIA VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')",
                info.MaMT, info.TenMT, info.MaLoaiMT, info.DungLuong, info.KichThuoc, info.Link);
                DataProvider.ExecuteNoneQuery(sql);
                return firstcode;
            }
            catch (Exception e)
            {

            }
            return -1;
        }

        public static List<int> ThemMultimedia(List<MultimediaDTO> list_info)
        {
            int firstcode = LayMaMulti();
            List<int> list_code = new List<int>();
            try
            {
                foreach (MultimediaDTO info in list_info)
                {
                    info.MaMT = firstcode;
                    list_code.Add(firstcode);
                    string sql = string.Format("insert into MULTIMEDIA VALUES('{0}', N'{1}', '{2}', '{3}', '{4}', '{5}')",
                    info.MaMT, info.TenMT, info.MaLoaiMT, info.DungLuong, info.KichThuoc, info.Link);
                    DataProvider.ExecuteNoneQuery(sql);

                    firstcode++;
                }
                return list_code;
            }
            catch (Exception e)
            {

            }
            return null;
        }
    }
}
